﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ecdl.demo.model;
using ecdl.demo.model.util;

namespace ecdl.demo.ui.ui.testselection {
    /// <summary>
    /// Interaction logic for TestSelectionWindow.xaml
    /// </summary>
    public partial class TestSelectionWindow : Window {

        private List<Test> allTests;

        private Dictionary<Object, Test> testButtons = new Dictionary<object, Test>();

        public event EventHandler<GenericEventArgs<Test>> TestSelectedEvent;

        public TestSelectionWindow() {
            InitializeComponent();
        }

        public TestSelectionWindow(List<Test> tests) {
            this.allTests = tests;
            InitializeComponent();

            foreach (var test in tests) {
                Button button = new Button();
                var bc = new BrushConverter();
                button.Background = (Brush)bc.ConvertFrom("#FF98BBE1");
                button.BorderBrush = (Brush)bc.ConvertFrom("#FF98BBE1");
                button.FontFamily = new FontFamily("Arial");
                button.FontSize = 18;
                button.Click += Modul2Button_Click;
                button.Content = test.Name;
                ButtonContainer.Children.Add(button);
                testButtons.Add(button, test);
            }
        }

        private void Modul2Button_Click(object sender, RoutedEventArgs e) {
            Test currentTest = testButtons[sender];
            FireTestSelectedEvent(currentTest);
        }

        private void FireTestSelectedEvent(Test selectedTest) {
            if (TestSelectedEvent != null) {
                TestSelectedEvent(this, new GenericEventArgs<Test>(selectedTest));
            }
        }
    }
}
